package Presenter;

import java.util.ArrayList;

import org.json.JSONException;
import org.json.JSONObject;

import Models.PackageTypeView;

public class PackageTypeViewPresenter extends AbstractPresenter<PackageTypeView> {
	final String SINGLEITEM = "packageTypeView";
	final String MULTIITEM = "packageTypeViews";
	
	public ArrayList<PackageTypeView> tryJSONParseArray(String input){
		return super.doJSONParseArray(input, SINGLEITEM, MULTIITEM);
	}
	
	public PackageTypeView tryJSONParse(String input){
		return super.doJSONParse(input, SINGLEITEM);
	}
	
	public PackageTypeView createItemFromJSONObject(JSONObject jsonObject){
		PackageTypeView item = new PackageTypeView();
		try{
			item.setPackageTypeID(jsonObject.getInt("packageTypeID"));
			item.setPackageDescription(jsonObject.getString("packageTypeDesc"));
			item.setPackageVolume(jsonObject.getDouble("packageTypeVol"));
			item.setNumItems(jsonObject.getInt("numItems"));
			item.setServingVessel(jsonObject.getBoolean("servingVessel"));
			
			return item;
		} catch(JSONException ex){
			ex.printStackTrace();
		} catch(Exception ex){
			ex.printStackTrace();
		}
		return null;
	}
	
	public JSONObject createJSON(PackageTypeView item){
		try{
			JSONObject json = new JSONObject();
			json.put("packageTypeID", item.getPackageTypeID());
			json.put("packageTypeDesc", item.getPackageDescription());
			json.put("packageTypeVol", item.getPackageVolume());
			json.put("numItems", item.getNumItems());
			json.put("servingVessel", item.isServingVessel());
			return json;
		} catch(JSONException ex){
			ex.printStackTrace();
		}
		return null;
	}
	
	public PackageTypeView getEmptyEntity(){
		PackageTypeView entity = new PackageTypeView();
		return entity;
	}
}
